package com.junmiao.A.postProcess;

import com.junmiao.A.stockModel.SohuStockBean;

public class SohuStockPostProcess {

	public static SohuStockBean postSohuStockBeanProcess(String resp) {

		SohuStockBean ssb = new SohuStockBean();

		// Get Stock Name and No
		int b = resp.indexOf("title");
		int eb = resp.indexOf("股票行情中心");

		if (b < 0 || eb < 0 || (eb - b) < 10) {
			return null;
		}

		String stock = resp.substring(b + 6, eb);
		String stockNo = stock.substring(stock.length() - 10,
				stock.length() - 4);
		String stockName = stock.substring(0, stock.length() - 11);

		ssb.setStockNo(stockNo);
		ssb.setStockName(stockName);

		int start = resp.indexOf("个股概况</h3>");

		if (start < 0) {
			resetSohuStockBean(ssb);
		}

		try {

			String tmp = resp.substring(start + 15);

			// ----------   zong gu ben ----------------
			int k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			int q =  tmp.indexOf("<");
			
			ssb.setZong_gu_bin(tmp.substring(1,q));
		
			// -----------  liu tong gu ben -------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			
			ssb.setLiu_tong_gu_ben(tmp.substring(1,q));
			
			// ------------ jin zi chan shou yi ----------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			
			ssb.setJin_zi_zhan_shou_yi_lv(tmp.substring(1,q));
			
			// ------------ biao xian 5 day --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setBiao_xian_5_day(tmp.substring(1,q));
			
			// ------------ huan shou 5 day --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setHuan_shou_5_day(tmp.substring(1,q));
			
			// ------------ mei gu shou yi --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setMei_gu_shou_yi(tmp.substring(1,q));
			
			// ------------ mei gu jin zi chan --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setMei_gu_jin_zi_chan(tmp.substring(1,q));
			
			// ------------ zhu yin shou ru zen zhang --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setZhu_yin_zen_zhan_lv(tmp.substring(1,q));
			
			// ------------ 10 day biao xian --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setBiao_xian_10_day(tmp.substring(1,q));	
			
			// ------------ 10 day huan shou --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setHuan_shou_10_day(tmp.substring(1,q));	
			
			// ------------ mei gu zi ben gong ji jin --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setMei_gu_zi_ben_gong_ji_jin(tmp.substring(1,q));	
			
			// ------------ mei gu wei fen pei li run --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setMei_gu_wei_fen_pei(tmp.substring(1,q));	
			
			// ------------ jin li run zeng zhang  --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setJin_li_zen_zhang(tmp.substring(1,q));	
			
			// ------------ 1 year high  --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setYearHigh(tmp.substring(1,q));	
			
			// ------------  1 year low --------------
			k = tmp.indexOf("<li");
			tmp = tmp.substring(k);
			k = tmp.indexOf(">");
			tmp =  tmp.substring(k+1);
			k =  tmp.indexOf(">");
			tmp =  tmp.substring(k);
			q =  tmp.indexOf("<");
			ssb.setYearLow(tmp.substring(1,q));	

			
			
		} catch (RuntimeException e) {
			resetSohuStockBean(ssb);
		}

		return ssb;

	}

	public static void resetSohuStockBean(SohuStockBean shsb) {
		shsb.setBiao_xian_10_day("0");
		shsb.setBiao_xian_5_day("0");
		shsb.setHuan_shou_10_day("0");
		shsb.setHuan_shou_5_day("0");
		shsb.setJin_zi_zhan_shou_yi_lv("0");
		shsb.setLiu_tong_gu_ben("0");
		shsb.setMei_gu_jin_zi_chan("0");
		shsb.setMei_gu_shou_yi("0");
		shsb.setMei_gu_zi_ben_gong_ji_jin("0");
		shsb.setZhu_yin_zen_zhan_lv("0");
		shsb.setZong_gu_bin("0");
		shsb.setJin_li_zen_zhang("0");
		shsb.setMei_gu_wei_fen_pei("0");
		shsb.setYearHigh("0");
		shsb.setYearLow("0");
	}

}
